const mongoTool={
    collect:null,
    use(collection){
        this.collect=collection
        
    },

    find(where={}, success){
        if(typeof where === "function"){
            success = where;
            where = {};
        }
       
        this.collect.find(where, {_id:0,__v:0}, (err, data)=>{
            if(err){
                console.log(err);
            }else{
                success(data)
            }
        })
    },
    sort(sort, where={}, success){
        if(typeof where === "function"){
            success = where;
            where = {};
        }
        this.collect.find(where, {_id:0,__v:0}).sort(sort).exec((err, data)=>{
            if(err){
                console.log(err);
            }else{
                success(data);
            }
        })
    },
    page(index, num, where, success){
        if(typeof where === "function"){
            success = where;
            where = {};
        }
        this.collect.find(where, {_id:0,__v:0}).limit(num).skip(index*num).exec((err, data)=>{
            if(err){
                console.log(err);
            }else{
                success(data);
            }
        })
    }
}

module.exports=mongoTool;